const logoPlayerMusic = {
  init(that) {
    const player = that.player;

    //音频缓冲事件
    player.onprogress = () => {};

    // 获取音乐时长
    player.onloadedmetadata = () => {
      console.log("onloadedmetadata");
      that.duration = player.duration;
    };

    //开始播放音乐
    player.onplay = () => {
      let timer;
      clearTimeout(timer);
      timer = setTimeout(() => {
        that.musicReady = true;
      }, 100);
    };
    //获取当前播放时间
    player.ontimeupdate = () => {
      that.currentTime = player.currentTime;
    };
    //当前音乐播放完毕
    player.onended = () => {
      that.next();
    };
    //音乐播放出错
    player.onerror = () => {
      that.next();
      if (player.src.indexOf("flac")) {
        console.log("flac播放出错");
      }
      console.log("播放出错啦！");
    };
    //音乐进度拖动大于加载时重载音乐
    player.onstalled = () => {
      player.load();
      that.play(false);
      let timer;
      clearTimeout(timer);
      timer = setTimeout(() => {
        that.play(true);
      }, 10);
    };
    //将能播放的音乐加入播放历史
    player.oncanplay = () => {
      // if (that.historyList.length === 0 || that.currentMusic.id !== that.historyList[0].id) {
      //     that.setHistory(that.currentMusic)
      // }
    };
  }
};

export default logoPlayerMusic;
